package com.it.goods.api;
import com.it.goods.entity.Goods;
import com.it.goods.service.GoodsService;
import com.it.goods.vo.GoodsVO;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService(version = "${goods.service.version}")
public class ApiGoodsImpl implements GoodsApi {

    @Autowired
    private GoodsService goodsService;
    public boolean addGoods(GoodsVO goodsVO) {
        Goods goods = new Goods();
        BeanUtils.copyProperties(goodsVO,goods);
        goodsService.insert(goods);
        return true;
    }

    public boolean delGoods(long goodsId) {
        goodsService.deleteById(goodsId);
        return true;
    }

    public boolean updateGoods(GoodsVO goodsVO) {
        Goods goods = new Goods();
        BeanUtils.copyProperties(goodsVO,goods);
        goodsService.updateById(goods);
        return true;
    }

    public GoodsVO queryGoodsById(long goodsId) {
        GoodsVO goodsVO = new GoodsVO();
        Goods goods = goodsService.selectById(goodsId);
        BeanUtils.copyProperties(goods, goodsVO);
        return goodsVO;
    }
}
